#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N = 1e6 + 10;
int ne[N];
string s;
int main()
{
	cin >> s;
	int n = s.size();
	s = " " + s;
	int ma = 0;
	for (int i = 2, j = 0; i <= n; i++) {
		while (j && s[i] != s[j + 1])j = ne[j];
		if (s[i] == s[j + 1])j++;
		ne[i] = j;
		if (i != n) {
			ma = max(ma, ne[i]);
		}
	}
	if (!ne[n]) {
		cout << "Just a legend" << endl;
		return 0;
	}
	int idx = ne[n];
	cout << "ma=" << ma << endl;
	while (idx > ma) {
		idx = ne[idx];
		cout << "idx=" << idx << endl;
	}
	if (!idx) {
		cout << "Just a legend" << endl;
		return 0;
	}
	for (int i = 1; i <= idx; i++) {
		cout << s[i];
	}	
	/*for (int i = idx - ne[idx] + 1; i <= idx; i++) {
		cout << s[i];
	}*/
	return 0;
}
